//
//  main.cpp
//  opencvtest
//
//  Created by 李勇 on 2019/4/27.
//  Copyright © 2019 李勇. All rights reserved.
//

#include <iostream>
#include <opencv2/opencv.hpp>
#include <string>

using namespace cv;
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    Mat image;
    
    string imageName("/Users/liyong/program/opencv/lena512color.tiff"); // by default
    if( argc > 1)
    {
        imageName = argv[1];
    }
    
    image = imread(imageName.c_str(), IMREAD_COLOR); // Read the file
    if( image.empty() )                      // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }
    
    imshow( "Hello world!", image );
    waitKey();
    
    /*显示rgb分量图像*/
    Mat rgbChannels[3];
    split(image, rgbChannels);
    imshow("Blue", rgbChannels[0]);
    imshow("Green", rgbChannels[1]);
    imshow("Red", rgbChannels[2]);
    waitKey();
    
    /*显示hsv分量图像*/
    Mat hsv, hsvChannels[3];
    cvtColor(image, hsv, COLOR_BGR2HSV);
    split(hsv, hsvChannels);
    imshow("Hue", hsvChannels[0]);
    imshow("Saturation", hsvChannels[1]);
    imshow("Value", hsvChannels[2]);
    waitKey();
    
    return 0;
}
